/*
 * User Manager Window
 */
MyDesktop.UserWindow = Ext.extend(Ext.app.Module, {
    id:'userManager',
    init : function(){
        this.launcher = {
            text: 'User Manager',
            iconCls:'icon-grid',
            handler : this.createWindow,
            scope: this
        }
		UserWindow = this;
    },

    createWindow : function(){
        var desktop = this.app.getDesktop();
        var win = desktop.getWindow('userManager');
		
		var fm = Ext.form;
		var Ed = Ext.grid.GridEditor;
        if(!win){
            win = desktop.createWindow({
                id: 'userManager',
                title:'User Manager',
                width:740,
                height:480,
                iconCls: 'icon-grid',
                shim:false,
                animCollapse:false,
                constrainHeader:true,

                layout: 'fit',
                items:
					new Ext.grid.EditorGridPanel({
                        border:false,
                        ds: new Ext.data.Store({
                            proxy: new Ext.data.HttpProxy({
								url: 'includes/sajax/sajaxUsers.php?getUsers=1'
						    }),
							
						    reader: new Ext.data.JsonReader({
						        root: 'Administrators',
						        id: 'UID'
						    }, [
						    {name: 'UID', mapping: 'UID'},
							{name: 'Delete', mapping: 'Delete'},
						    {name: 'FullName', mapping: 'FullName'},
							{name: 'Email', mapping: 'Email'},
							{name: 'Userid', mapping: 'Userid'},
							{name: 'Password', mapping: 'Password'},
							{name: 'AdminLevel', mapping: 'AdminLevel'}
						    ]),
							autoLoad: true,
						}),	
                        cm: new Ext.grid.ColumnModel([
							{dataIndex: 'UID', hidden: 'true'}
							,{dataIndex: 'Delete', align: 'center', width: 40, header: ""}
							,{
							 	header:    "Name", 
								width:     200, 
								sortable:  true, 
								dataIndex: 'FullName',
								editor: new Ed(new fm.TextField({
					            	allowBlank: true
					           	}))
							}
							,{
								header: "Email Address", 
								align: 'left', 
								width: 200, 
								sortable: true, 
								dataIndex: 'Email',
								editor: new Ed(new fm.TextField({
					            	allowBlank: true
					           	}))
							}
							,{
								header: "User Name", 
								width: 100, 
								sortable: true, 
								dataIndex: 'Userid',
								editor: new Ed(new fm.TextField({
					            	allowBlank: true
					           	}))
							}
							,{
								header: "Password", 
								width: 100, 
								sortable: true, 
								dataIndex: 'Password',
								editor: new Ed(new fm.TextField({
					            	allowBlank: true
					           	}))
							}
							,{
								header: "User Level", 
								width: 100, 
								sortable: true, 
								dataIndex: 'AdminLevel',
								editor: new Ed(new Ext.form.ComboBox({
					               typeAhead: true,
					               lazyRender:true
					            }))
							}
						]),
                        viewConfig: {
                            forceFit:true
                        },
                        
                        tbar:[{
                            text:'Add User',
                            tooltip:'Add a new user',
                            iconCls:'add'
                        }, '-',{
                            text:'Delete User',
                            tooltip:'Remove the selected user',
							iconCls:'remove'
                        }]
                    })
            });
        }
		win.show();
    },
	closeWindow : function() {
		var desktop = this.app.getDesktop();
        var win = desktop.getWindow('userManager');
		if (win) {
			win.close();
		}	
	}
});